<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');

get_config_keytable("workclass");
empty($do) && $do = 'list';
if ($do == 'list') {
	$id = getGP('id','G','int');
	if (user_union_id!='') {
		$wheresql = " AND unionid='".user_union_id."'";
	}else{
		$wheresql = " AND unionid='".union_id."'";
	}
	$blog = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workclass  WHERE id = '$id' ".$wheresql."");
	//获取模块
	$tpl = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workclass_template  WHERE id = '".$blog['worktemplate']."' ".$wheresql." ");
	//获取当前流程
	$pflow= $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workclass_flow WHERE template_id='".$tpl["id"]."' and type_id='".$tpl["workclasstype"]."' and id='".$_GET["flowid"]."' ".$wheresql." ");
	
	
	include_once('template/views_key.php');
}elseif ($do == 'save') {
	get_union_add();
	$savetype = getGP('savetype','P');
	$id = getGP('id','P','int');
	$userkey = getGP('userkey','P');
	$lnstructions = getGP('lnstructions','P');
	$flowid = getGP('flowid','P');
	$type = getGP('type','P');
	$workclassid = getGP('workclassid','P');
	$bid = getGP('bid','P');
	if($type=='2'){
		$workclass = array(
			'type' => '1'
		);
		update_db('workclass',$workclass, array('id' => $workclassid));
	}
	$workclass_personnel_update = array(
		'approvaldate' => get_date('Y-m-d H:i:s',PHP_TIME),
		'lnstructions' => $lnstructions,
		'type' => '1'
	);
	update_db('workclass_personnel',$workclass_personnel_update, array('id' => $bid));
	if(getGP('getflowid','P')!='1' && $type!='2' && getGP('userkey','P')!=''){
	$workclass_personnel = array(
		'name' => getGP('userkey','P'),
		'uid' => getGP('userkeyid','P'),
		'designationdate' => get_date('Y-m-d H:i:s',PHP_TIME),
		'type' => '3',
		'flowid' => $flowid,
		'workclassid' => $workclassid,
		'unionid' => union_id
	);
	insert_db('workclass_personnel',$workclass_personnel);
	}
	
	if(getGP('sms_info_box_shownamemaster','P')!=''){
	$content='您有一个工作流程需要审批,请点击查看!<a href="admin.php?ac=workkey&fileurl=work&type=3">点击审批>></a>';
	//接收人；内容；类型（1：有返回回值;0：无返回值）;URL
	SMS_ADD_POST(getGP('userkey','P'),$content,0,0,$_USER->id);
	}
	//手机短信
	if(getGP('sms_phone_box_shownamemaster','P')!=''){
	$content='您有一个工作流程需要审批,请登录OA进行审批!';
	PHONE_ADD_POST(getGP('userkeyphone','P'),$content,getGP('userkey','P'),0,0,$_USER->id);
	}
	goto_page('admin.php?ac=workkey&fileurl=work&type=3');


}
?>